from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

# 导入视图模块
from .views.othes_views import custom_403, login, switch_role, switch_role_submit, index
from .views import chapter_views, class_evaluation_views, course_period_views, class_course_views
from .views import class_task_todo_views, homework_views, log_views, manage_views, mistake_views
from .views import notification_views, subject_chapter_views, student_views, student_performance
from .views import attendance_views,  doubao_views, class_teacher_views, grade_schedule_views
from .views.grade_leader_views import GradeLeaderDashboardView
from .views.principal_views import PrincipalDashboardView
from .views.class_teacher_views import TeacherDashboardView


from .views.class_evaluation_views import (
    ClassEvaluationListView, ClassEvaluationCreateView,
    ClassEvaluationUpdateView, ClassEvaluationDeleteView
)

from .views.class_task_todo_views import (
    ClassTaskTodoListView, ClassTaskTodoDetailView,
    ClassTaskTodoCreateView, ClassTaskTodoUpdateView,
    ClassTaskTodoDeleteView, get_tasks
)
from .views.homework_views import (
    homework_records_detail,
    HomeworkListView, HomeworkCreateView, HomeworkUpdateView, HomeworkDeleteView,
    HomeworkSubmissionListView, HomeworkSubmissionCreateView,
    HomeworkSubmissionUpdateView, HomeworkSubmissionDeleteView,
    class_homework_stats
)
from .views.attendance_views import (
    get_attendance_records, update_attendance_records, get_student_status
)
from .views.knowledge_point.knowledge_point_create import knowledge_point_create
from .views.knowledge_point.knowledge_point_list import knowledge_point_list
from .views.knowledge_point.knowledge_point_update import knowledge_point_update
from .views.knowledge_point.knowledge_point_delete import knowledge_point_delete_view, knowledge_point_ajax_delete
from .views.schedule_manager_views import ScheduleManager
from .views.course_period_traditional_views import (
    course_period_list,
    course_period_create,
    course_period_update,
    course_period_delete
)

# 核心URL配置
# 该文件包含教育管理系统的所有URL路由配置
# 路由按功能模块分组，便于维护和扩展

app_name = 'core'
handler403 = 'core.views.othes_views.custom_403'  # 自定义403错误处理视图

urlpatterns = [
    # 基础功能路由
    path('', index, name='index'),  # 首页
    path('login/', login, name='login'),  # 登录页面
    path('switch_role', switch_role, name='switch_role'),  # 角色切换页面
    path('switch_role_submit/<str:rolename>/', switch_role_submit, name='switch_role_submit'),  # 提交角色切换


    # 校长功能
    path('principal/dashboard/', PrincipalDashboardView.as_view(), name='principal_dashboard'),
    # 年级组长功能
    path('grade-leader/dashboard/<int:grade_id>/', GradeLeaderDashboardView.as_view(), name='grade_leader_dashboard'),
    #班主任仪表盘
    path('hometeacher/dashboard/<int:class_id>/', manage_views.home_teacher_dashboard, name='home_teacher_dashboard'),
    #教师功能
    path('teacher/dashboard/', TeacherDashboardView.as_view(), name='teacher_dashboard'),

    # 班级课程管理
    path('class-courses/', class_course_views.class_course_list, name='class_course_list'),
    path('class-courses/create/', class_course_views.class_course_create, name='class_course_create'),
    path('class-courses/<int:pk>/', class_course_views.class_course_detail, name='class_course_detail'),
    path('class-courses/<int:pk>/update/', class_course_views.class_course_update, name='class_course_update'),
    path('class-courses/<int:pk>/delete/', class_course_views.class_course_delete, name='class_course_delete'),
    path('class-courses/class/<int:class_id>/', class_course_views.get_course_by_classid, name='get_course_by_classid'),
    path('class-courses/detail/<int:pk>/', class_course_views.get_class_course_detail, name='get_class_course_detail'),
    path('class-courses/update/<int:pk>/', class_course_views.class_course_update_ajax, name='update_class_course'),
    path('class-courses/delete/<int:pk>/', class_course_views.class_course_delete_ajax, name='delete_class_course'),
   # 年级日程表管理
    path('grade-schedules/', grade_schedule_views.grade_schedule_list, name='grade_schedule_list'),
    path('grade-schedules/grade/<int:grade_id>/', grade_schedule_views.grade_schedule_list, name='grade_schedule_list_by_id'),
    path('grade-schedules/create/', grade_schedule_views.grade_schedule_create, name='grade_schedule_create'),
    path('grade-schedules/<int:pk>/', grade_schedule_views.get_grade_schedule_detail, name='grade_schedule_detail'),
    path('grade-schedules/<int:pk>/update/', grade_schedule_views.grade_schedule_update, name='grade_schedule_update'),
    path('grade-schedules/<int:pk>/delete/', grade_schedule_views.grade_schedule_delete, name='grade_schedule_delete'),
    path('grade-schedules/detail/<int:pk>/', grade_schedule_views.get_grade_schedule_detail, name='get_grade_schedule_detail'),
    path('schedules/grade/<int:grade_id>/', grade_schedule_views.get_grade_schedule_by_gradeid, name='grade_schedule_by_gradeid'),
    path('grade-schedules/generate-month/', grade_schedule_views.generate_month_schedule, name='generate_month_schedule'),
   
   
    # 课程时间段管理
    path('course-periods/<int:pk>/', course_period_views.get_course_period, name='get_course_period'),
    path('course-periods/create/', course_period_views.create_course_period, name='create_course_period'),
    path('course-periods/<int:pk>/update/', course_period_views.update_course_period, name='update_course_period'),
    path('course-periods/<int:pk>/delete/', course_period_views.delete_course_period, name='delete_course_period'),

    # 传统课程时间段管理视图
    path('course-periods-traditional/', course_period_list, name='course_period_list'),
    path('course-periods-traditional/create/', course_period_create, name='course_period_create'),
    path('course-periods-traditional/<int:pk>/update/', course_period_update, name='course_period_update'),
    path('course-periods-traditional/<int:pk>/delete/', course_period_delete, name='course_period_delete'),

    # 班级课程评估
    path('class-evaluations/<int:class_id>/', ClassEvaluationListView.as_view(), name='class_evaluation_list'),
    path('class-evaluations/create/', ClassEvaluationCreateView.as_view(), name='class_evaluation_create'),
    path('class-evaluations/<int:pk>/update/', ClassEvaluationUpdateView.as_view(), name='class_evaluation_update'),
    path('class-evaluations/<int:pk>/delete/', ClassEvaluationDeleteView.as_view(), name='class_evaluation_delete'),


    # 错题管理
    path('mistakes/', mistake_views.mistake_list, name='mistake_list'),
    path('mistakes/create/', mistake_views.mistake_create, name='mistake_create'),
    path('mistakes/<int:pk>/update/', mistake_views.mistake_update, name='mistake_update'),
    path('mistake/export-preview/', mistake_views.MistakeExportPreviewView.as_view(), name='mistake_export_preview'),
    path('mistake/export-word/', mistake_views.mistake_export_word, name='mistake_export_word'),
    path('mistakes/<int:pk>/delete/', mistake_views.mistake_delete, name='mistake_delete'),
    path('mistakes/get-mistake-text/', mistake_views.get_mistake_text, name='get_mistake_text'),
    path('upload-image/', mistake_views.upload_image, name='upload_image'),
    path('analyze-image/', mistake_views.analyze_image, name='analyze_image'),

    # 章节管理
    path('chapters/', chapter_views.chapter_list, name='chapter_list'),
    path('chapters/create/', chapter_views.chapter_create, name='chapter_create'),
    path('chapters/<int:pk>/update/', chapter_views.chapter_update, name='chapter_update'),
    path('chapters/<int:pk>/delete/', chapter_views.chapter_delete, name='chapter_delete'),

    # 通知管理
    path('notifications/', notification_views.notification_list, name='notification_list'),
    path('notifications/send/', notification_views.send_notification, name='send_notification'),
    path('notifications/<int:pk>/', notification_views.notification_detail, name='notification_detail'),
    path('notifications/<int:pk>/delete/', notification_views.delete_notification, name='delete_notification'),

    # 知识点管理
    path('chapters/<int:chapter_id>/knowledge-points/', knowledge_point_list, name='knowledge_point_list'),
    path('knowledge-points/create/', knowledge_point_create, name='knowledge_point_create'),
    path('knowledge-points/<int:pk>/update/', knowledge_point_update, name='knowledge_point_update'),
    path('knowledge-points/<int:pk>/delete/', knowledge_point_delete_view, name='knowledge_point_delete'),
    path('subject-chapter-knowledge/<int:subject_id>/', subject_chapter_views.subject_chapter_knowledge, name='subject_chapter_knowledge'),
    # 知识点管理AJAX接口
    path('ajax/chapters/', mistake_views.ajax_chapters, name='ajax_chapters'),
    path('ajax/knowledge-points/', mistake_views.ajax_knowledge_points, name='ajax_knowledge_points'),
    path('ajax/knowledge-point/create/', knowledge_point_create, name='knowledge_point_create'),
    path('ajax/knowledge-point/update/', knowledge_point_update, name='knowledge_point_update'),
    path('ajax/knowledge-point/delete/', knowledge_point_ajax_delete, name='knowledge_point_ajax_delete'),

    # 班级教师功能
    path('class-teacher/student-comment/management/', class_teacher_views.student_comment_management, name='student_comment_management'),
    path('class-teacher/student-comment/edit/<int:student_id>/<int:class_id>/<int:semester_id>/', class_teacher_views.student_comment_edit, name='student_comment_edit'),
    path('student-comment/export-to-word/', class_teacher_views.export_comments_to_word, name='export_comments_to_word'),
    path('api/generate-comment/', doubao_views.generate_student_comment, name='generate_student_comment'),
    
    # 日程管理模块

    path('schedule-manager/', ScheduleManager.index, name='schedule_manager_index'),
    path('schedule-manager/class/<int:class_id>/', ScheduleManager.schedule_manager_list, name='schedule_manager_class_list'),
    path('schedule-manager/grade/<int:grade_id>/', ScheduleManager.schedule_manager_grade_list, name='schedule_manager_grade_list'),
    path('schedule-manager/list/', ScheduleManager.schedule_manager_list, name='schedule_manager_list'),
    # 班级课程列表路由
    path('schedule-manager/class-courses/', ScheduleManager.class_course_list, name='schedule_manager_class_course_list'),
    path('schedule-manager/class-courses/class/<int:class_id>/', ScheduleManager.class_course_list, name='schedule_manager_class_course_list_by_id'),
    # 教师课程列表路由
    path('schedule-manager/teacher-courses/class/<int:class_id>/', ScheduleManager.teacher_course_list, name='schedule_manager_teacher_course_list'),
  
    # 添加schedule_delete_ajax的URL配置
  
  
   
    # 课程表管理
    
    
    
    # 班级任务待办事项
    path('tasks/', ClassTaskTodoListView.as_view(), name='task_list'),
    path('tasks/<int:pk>/', ClassTaskTodoDetailView.as_view(), name='task_detail'),
    path('tasks/create/', ClassTaskTodoCreateView.as_view(), name='task_create'),
    path('tasks/<int:pk>/update/', ClassTaskTodoUpdateView.as_view(), name='task_update'),
    path('tasks/<int:pk>/delete/', ClassTaskTodoDeleteView.as_view(), name='task_delete'),
    path('tasks/get/<int:classid>/', get_tasks, name='get_tasks'),

    # 学生管理
    path('students/', student_views.student_list, name='student_list'),
    path('students/create/', student_views.student_create, name='student_create'),
    path('students/<int:pk>/update/', student_views.student_update, name='student_update'),
    path('students/<int:pk>/delete/', student_views.student_delete, name='student_delete'),

    # 考勤管理
    path('attendance_records/', get_attendance_records, name='attendance_records'),
    path('update_attendance_records', update_attendance_records, name='update_attendance_records'),
    path('get_student_status/<int:classid>/<str:selected_date>', get_student_status, name='get_student_status'),

    # 学生在校表现
    path('student_performance/<int:student_id>/<str:strdate>/', student_performance, name='student_performance'),

    # 作业管理
    path('homework/', HomeworkListView.as_view(), name='homework_list'),
    path('homework/create/', HomeworkCreateView.as_view(), name='homework_create'),
    path('homework/<int:pk>/update/', HomeworkUpdateView.as_view(), name='homework_update'),
    path('homework/<int:pk>/delete/', HomeworkDeleteView.as_view(), name='homework_delete'),
    path('homework_records_detail/<int:homework_id>/', homework_records_detail, name='homework_records_detail'),
    path('class_homework_stats/<int:classid>/<str:date_str>/', class_homework_stats, name='class_homework_stats'),

    # 作业提交管理
    path('homework_submissions/', HomeworkSubmissionListView.as_view(), name='homework_submission_list'),
    path('homework_submissions/create/', HomeworkSubmissionCreateView.as_view(), name='homework_submission_create'),
    path('homework_submissions/<int:pk>/update/', HomeworkSubmissionUpdateView.as_view(), name='homework_submission_update'),
    path('homework_submissions/<int:pk>/delete/', HomeworkSubmissionDeleteView.as_view(), name='homework_submission_delete'),

    # 管理模块

    path('day_manage/<int:classid>/', manage_views.day_manage, name='day_manage'),
    path('week_manage/<int:classid>/<str:strdate>/', manage_views.week_manage, name='week_manage'),
    path('month_manage/<int:classid>/<str:strdate>/', manage_views.month_manage, name='month_manage'),
    path('term_manage/<int:classid>/', manage_views.term_manage, name='term_manage'),

    # 请假管理
    path('leave-requests/', manage_views.LeaveRequestListView.as_view(), name='leave_request_list'),
    path('leave-requests/create/', manage_views.LeaveRequestCreateView.as_view(), name='leave_request_create'),
    path('leave-requests/<int:pk>/update/', manage_views.LeaveRequestUpdateView.as_view(), name='leave_request_update'),
    path('leave-requests/<int:pk>/delete/', manage_views.LeaveRequestDeleteView.as_view(), name='leave_request_delete'),

    # 纪律管理
    path('discipline-types/', manage_views.DisciplineTypeListView.as_view(), name='discipline_type_list'),
    path('discipline-types/create/', manage_views.DisciplineTypeCreateView.as_view(), name='discipline_type_create'),
    path('discipline-types/<int:pk>/update/', manage_views.DisciplineTypeUpdateView.as_view(), name='discipline_type_update'),
    path('discipline-types/<int:pk>/delete/', manage_views.DisciplineTypeDeleteView.as_view(), name='discipline_type_delete'),
    path('discipline-records/', manage_views.DisciplineRecordListView.as_view(), name='discipline_record_list'),
    path('discipline-records/create/', manage_views.DisciplineRecordCreateView.as_view(), name='discipline_record_create'),
    path('discipline-records/<int:pk>/update/', manage_views.DisciplineRecordUpdateView.as_view(), name='discipline_record_update'),
    path('discipline-records/<int:pk>/delete/', manage_views.DisciplineRecordDeleteView.as_view(), name='discipline_record_delete'),
    path('discipline-appeals/', manage_views.DisciplineAppealListView.as_view(), name='discipline_appeal_list'),
    path('discipline-appeals/create/', manage_views.DisciplineAppealCreateView.as_view(), name='discipline_appeal_create'),
    path('discipline-appeals/<int:pk>/update/', manage_views.DisciplineAppealUpdateView.as_view(), name='discipline_appeal_update'),
    path('discipline-appeals/<int:pk>/delete/', manage_views.DisciplineAppealDeleteView.as_view(), name='discipline_appeal_delete'),

    # 荣誉管理
    path('honor-types/', manage_views.HonorTypeListView.as_view(), name='honor_type_list'),
    path('honor-types/create/', manage_views.HonorTypeCreateView.as_view(), name='honor_type_create'),
    path('honor-types/<int:pk>/update/', manage_views.HonorTypeUpdateView.as_view(), name='honor_type_update'),
    path('honor-types/<int:pk>/delete/', manage_views.HonorTypeDeleteView.as_view(), name='honor_type_delete'),
    path('honor-records/', manage_views.HonorRecordListView.as_view(), name='honor_record_list'),
    path('honor-records/create/', manage_views.HonorRecordCreateView.as_view(), name='honor_record_create'),
    path('honor-records/<int:pk>/update/', manage_views.HonorRecordUpdateView.as_view(), name='honor_record_update'),
    path('honor-records/<int:pk>/delete/', manage_views.HonorRecordDeleteView.as_view(), name='honor_record_delete'),

    # 日志管理
    path('logs/', log_views.log_list, name='log_list'),

    # 第三方集成
    path('ckeditor/', include('ckeditor_uploader.urls')),  # CKEditor富文本编辑器
]

# 开发环境配置 - 媒体文件访问支持
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

# 配置媒体文件URL
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
